package com.wengu.game;

import cn.hutool.core.util.RandomUtil;

import java.util.Scanner;

/**
 * 猜数字游戏
 * @author wanghailei
 * @date 2023/01/03
 */
public class GameGuessNumberAuto {
    public static void main(String[] args) {
        System.out.println("==============欢迎来到猜数字游戏=================");
        System.out.println("=============================================");
        System.out.println("===================游戏规则===================");
        System.out.println("游戏参与者出一个数字，让电脑来猜你输入的数字，");
        System.out.println("每次猜完后，会提示电脑猜的的数字是大了还是小了，");
        System.out.println("然后电脑可继续猜，直到猜对为止");
        System.out.println("请输入数字：");
        Scanner input = new Scanner(System.in);
        int randomInt = input.nextInt();
        int min = 1;
        // 包含
        int max = 99;
        if (randomInt < min || randomInt > max){
            System.out.println("请输入100（不包含）以内的正数");
        }
        int small = min;
        int big = max;
        int number = min;
        while (true){
            number = (big + small)/2;
            System.out.println("电脑猜的数字是："+number);
            if (number == randomInt) {
                System.out.println("恭喜你，猜对了！");
                System.out.println(">>>>>>666666666666666666>>>>>>");
                break;
            } else if (number < randomInt) {
                System.out.println("电脑猜的数字小了");
                small = number;
            } else {
                System.out.println("电脑猜的数字大了");
                big = number;
            }
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            System.out.println("==========================================");
            System.out.println("==========================================");
        }
    }
}
